package com.wyz.config;

import org.apache.http.HttpHost;
import org.apache.http.impl.nio.client.HttpAsyncClientBuilder;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;

/***
 * ElasticSearch配置类
 * @Author 无涯子
 * @Date 2024-04-08
 */
@Configuration
public class ElasticSearchConfig {
    @Value("${elasticsearch_host}")
    private String host;
    @Value("${elasticsearch_port}")
    private Integer port;
    private final static String SCHEME = "http";

    @Bean
    public RestHighLevelClient restHighLevelClient(){
        return new RestHighLevelClient(RestClient.builder(new HttpHost(host,port,SCHEME)));
    }

    @Bean
    public ElasticsearchRestTemplate elasticsearchRestTemplate(){
        return new ElasticsearchRestTemplate(restHighLevelClient());
    }
}
